package com.weayer.controller;

import com.weayer.constant.DriverConstants;
import com.weayer.dto.DriverUser;
import com.weayer.dto.ResponseResult;
import com.weayer.mapper.DriverUserMapper;
import com.weayer.response.DriverUserResponse;
import com.weayer.response.OrderDriverResponse;
import com.weayer.service.DriverUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: Service服务 - 司机 - 司机管理Controller
 * @author: Weayer
 **/
@RestController
public class DriverUserController {
    @Autowired
    private DriverUserService driverUserService;
    @Autowired
    private DriverUserMapper driverUserMapper;

    @PostMapping("/user")
    public ResponseResult addUser(@RequestBody DriverUser driverUser){
        return driverUserService.addDriverUser(driverUser);
    }
    @PutMapping("/user")
    public ResponseResult updateUser(@RequestBody DriverUser driverUser){
        return driverUserService.updateDriverUser(driverUser);
    }
    @GetMapping("/check-driver/{driverPhone}")
    public ResponseResult<DriverUserResponse> checkDriver(@PathVariable("driverPhone") String driverPhone){
        ResponseResult<DriverUser> driverUserByPhone = driverUserService.getDriverUserByPhone(driverPhone);
        DriverUser driverUserDB = driverUserByPhone.getData();
        int ifExists = DriverConstants.DRIVER_USER_NOT_EXISTS;
        if(driverUserDB != null){
            ifExists = DriverConstants.DRIVER_USER_EXISTS;
        }
        DriverUserResponse driverUserResponse = new DriverUserResponse();
        driverUserResponse.setDriverPhone(driverPhone);
        driverUserResponse.setIfExists(ifExists);
        return ResponseResult.success(driverUserResponse);
    }
    @GetMapping("/get-available-driver/{carId}")
    public ResponseResult<OrderDriverResponse> getAvailableDriver(@PathVariable("carId") Long carId){
        return driverUserService.getAvailableDriver(carId);
    }
    @GetMapping("/test-xml")
    public int testXml(String cityCode){
        return driverUserMapper.selectCountByCityCode(cityCode);
    }
}
